//从本地获取个人信息的数据
var username = document.getElementsByClassName("username")[0];
username.value = localStorage.getItem("username");
var sex = document.getElementsByClassName("sex")[0];
sex.value = localStorage.getItem("usergender");
var tel = document.getElementsByClassName("tel")[0];
tel.value = localStorage.getItem("userphone");
var account = document.getElementsByClassName("account")[0];
account.value = localStorage.getItem("useraccount");
var password = document.getElementsByClassName("password")[0];
password.value = localStorage.getItem("userpassword");


//点击修改，修改信息
var content4 = document.getElementsByClassName("content4")[0];
//修改按钮
var remove = content4.getElementsByClassName("remove")[0];
//个人信息框
var contentRight = document.getElementById("contentRight");
//修改信息框
var contentRight1 = document.getElementById("contentRight1");
//点击修改按钮,个人信息框消失，修改信息框出现
remove.onclick = function(){
    contentRight.style.display = "none";
    contentRight1.style.display = "block";
    contentRight1.style.display = "flex";

    //从本地获取个人信息的数据
    var username1 = document.getElementsByClassName("username1")[0];
    username1.value = localStorage.getItem("username");
    var sex1 = document.getElementsByClassName("sex1")[0];
    sex1.value = localStorage.getItem("usergender");
    var tel1 = document.getElementsByClassName("tel1")[0];
    tel1.value = localStorage.getItem("userphone");
    var account1 = document.getElementsByClassName("account1")[0];
    account1.value = localStorage.getItem("useraccount");
    var password1 = document.getElementsByClassName("password1")[0];
    password1.value = localStorage.getItem("userpassword");


}

//点击确定或取消按钮，修改信息框消失，个人信息框出现
var sure = document.getElementsByClassName("sure")[0];
var cancel = document.getElementsByClassName("cancel")[0];
sure.onclick = function(){
    contentRight1.style.display = "none";
    contentRight.style.display = "block";
    contentRight.style.display = "flex";

    var username1 = document.getElementsByClassName("username1")[0];
    var sex1 = document.getElementsByClassName("sex1")[0];
    var tel1 = document.getElementsByClassName("tel1")[0];
    var account1 = document.getElementsByClassName("account1")[0];
    var password1 = document.getElementsByClassName("password1")[0];
    var userid = localStorage.getItem("userid");
    var userrole = localStorage.getItem("userrole");
    var userdept = localStorage.getItem("userdept");
    if(userrole == "老师"){
        userrole=2
    }else if(userrole == "学生"){
        userrole=3
    }
    var Json2 = {
        userPassword:password1.value,
        userId:Number(userid),
        userName:username1.value,
        userGender:sex1.value,
        userRole:userrole,
        userPhone:tel1.value,
        userDept:userdept
    }
    console.log(Json2);
    ajax.post(ajax.myUrl+"users/updateUser",Json2,function(result){
        console.log(result);
        localStorage.setItem("username",username1.value);
        localStorage.setItem("userphone",tel1.value);
        localStorage.setItem("usergender",sex1.value);
    })
}

cancel.onclick = function(){
    contentRight1.style.display = "none";
    contentRight.style.display = "block";
    contentRight.style.display = "flex";
}